#include "RingQueue.hpp"

void *Consumer(void *args)
{
    RingQueue<int> *rq=( RingQueue<int> *)args;
   int i=0;
    while(true)
    {
        //sleep(1);
        rq->Pop(&i);
        cout<<"消费者->"<<pthread_self()<<" "<<i<<endl;

    }
}
int j=0;
void *Producer(void *args)
{
    RingQueue<int> *rq=( RingQueue<int> *)args;
   
    while(true)
    {
        sleep(1);
         cout<<"生产者->"<<pthread_self()<<" "<<j<<endl;
       rq->Push(j++);
       
        
    }
   
}
int main()
{
    RingQueue<int> *rq = new RingQueue<int>();
    //pthread_t c,p;

    pthread_t c[2], p[3];
    pthread_create(c, nullptr, Consumer, (void *)rq);
    pthread_create(c + 1, nullptr, Consumer, (void *)rq);
    pthread_create(p, nullptr, Producer, (void *)rq);
    pthread_create(p + 1, nullptr, Producer, (void *)rq);
    pthread_create(p + 2, nullptr, Producer, (void *)rq);
    for (int i = 0; i < 2; i++)
    {
        pthread_join(c[i], nullptr);
    }
    for (int j = 0; j < 3; j++)
    {
        pthread_join(p[j], nullptr);
    } 
    /* pthread_join(c,nullptr);
    pthread_join(p,nullptr);
 */
    return 0;
}